#!/usr/bin/env bash

# ----------------------------------------------------------------------
# Filename:   01-packages-lv4.sh
# Version:    1.0
# Date:       2020/04/23
# Author:     Lz
# Email:      lz843723683@163.com
# History：     
#             Version 1.0, 2020/04/22
# Function:   packages - 01.测试安全四级-默认服务和软件包
# Out:        
#              0 => TPASS
#              1 => TFAIL
#              other=> TCONF
# ----------------------------------------------------------------------

## TODO : 测试收尾清除工作
#
PkgClean_FTLV4(){
	return $TPASS
}


## TODO: 调用程序退出函数
#    In: $1 => 调用脚本结果值
PkgExit_FTLV4(){
        # 调用退出函数，其中调用了clean相关函数
	Exit_FTLIB ${1}
}


## TODO: 用户界面
#
PkgUSAGE_FTLV4(){
	USAGE_FTLIB "安全四级测试 - 默认服务和软件包"
}


## TODO : 测试前的初始化 
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other=> TCONF
PkgInit_FTLV4(){
        # 调用初始化函数
	Init_FTLIB "PkgClean_FTLV4"
        # 调用用户界面函数
 	PkgUSAGE_FTLV4
}


## TODO ：默认自启动sshd、psacct、network、iptables、crond、auditd、rsyslog、firewalld  kdump服务
#
PkgTest01_FTLV4(){
	# 判断是否存在iptables
        SvcExist_FTLIB "isExist" "yes" "iptables"
	if [ $? -eq ${TPASS} ];then
	        local svcArr="sshd psacct network crond auditd rsyslog iptables"
	else
        	local svcArr="sshd psacct network crond auditd rsyslog firewalld"
	fi

        SvcActiveArr_FTLIB "isActive" "no" "$svcArr"
        RetParse_FTLIB "要求已经激活以下服务 ${svcArr}" "False"

        SvcEnableArr_FTLIB "isEnable" "no" "$svcArr"
        RetParse_FTLIB "要求开机自启动以下服务 ${svcArr}" "False"
}


## TODO ：默认存在sshd、psacct、network、iptables、crond、auditd、rsyslog、smartd、sysstat、firewalld  kdump服务
#
PkgTest02_FTLV4(){
        local svcArr="smartd sysstat"

        SvcExistArr_FTLIB "isExist" "no" "$svcArr"
        RetParse_FTLIB "要求存在以下服务 ${svcArr}" "False"
}


## TODO ：默认开启acpid 服务
#
PkgTest03_FTLV4(){
	AcpidEnable_FTGENREQ
}


## TODO ：默认安装rsync、openssl、openssl-devel、libaio、libaio-devel、libpng-devel、 pygobject2-devel、 libSM-devel、 libXrender-devel、 libXext-devel、ncurses-devel 、libXt-devel
#
PkgTest04_FTLV4(){
	local pkgArr="rsync openssl openssl-devel libaio libaio-devel libpng-devel pygobject2-devel libSM-devel libXrender-devel libXext-devel ncurses-devel libXt-devel"

	PkgExistArr_FTLIB "isExist" "no" "yes" "$pkgArr"
	RetParse_FTLIB "要求默认安装：$pkgArr" "False"
}


## TODO : Main
#  Out  : 
#         0 => TPASS
#         1 => TFAIL
#         other => TCONF
PkgMain_FTLV4(){
	PkgInit_FTLV4

	PkgTest01_FTLV4

	PkgTest02_FTLV4

	PkgTest03_FTLV4

	PkgTest04_FTLV4

	return ${TPASS}	
}

PkgMain_FTLV4
PkgExit_FTLV4 $?
